package com.eva.admin.api.system;

import com.eva.admin.biz.system.notice.dto.UpdateSystemNoticeStatusDTO;
import com.eva.admin.dao.system.notice.vo.SystemNoticeVO;
import com.eva.framework.common.api.BaseController;
import com.eva.admin.biz.system.notice.SystemNoticeBiz;
import com.eva.admin.biz.system.notice.dto.UpdateSystemNoticeDTO;
import com.eva.admin.biz.system.notice.dto.CreateSystemNoticeDTO;
import com.eva.framework.rbac.authorize.ContainPermissions;
import com.eva.framework.security.prevent.PreventRepeat;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.common.model.PageData;
import com.eva.framework.common.model.PageWrap;
import com.eva.admin.dao.system.notice.dto.QuerySystemNoticeDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "系统通知")
@RestController
@RequestMapping("/system/notice")
public class SystemNoticeController extends BaseController {

    @Resource
    private SystemNoticeBiz systemNoticeBiz;

    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @ContainPermissions("system:notice:create")
    public ApiResponse<?> create(@RequestBody CreateSystemNoticeDTO dto) {
        systemNoticeBiz.create(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @ContainPermissions("system:notice:delete")
    public ApiResponse<?> deleteById(@PathVariable Integer id) {
        systemNoticeBiz.deleteById(id);
        return ApiResponse.success(null);
    }

    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @ContainPermissions("system:notice:delete")
    public ApiResponse<?> deleteByIdInBatch(@RequestParam String ids) {
        systemNoticeBiz.deleteByIdInBatch(this.getIdList(ids));
        return ApiResponse.success(null);
    }

    @ApiOperation("修改")
    @PostMapping("/updateById")
    @ContainPermissions("system:notice:update")
    public ApiResponse<?> updateById(@RequestBody UpdateSystemNoticeDTO dto) {
        systemNoticeBiz.updateById(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("修改通知状态")
    @PostMapping("/updateStatus")
    @ContainPermissions("system:notice:update")
    public ApiResponse<?> updateStatus(@RequestBody UpdateSystemNoticeStatusDTO dto) {
        systemNoticeBiz.updateStatus(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    @ContainPermissions("system:notice:query")
    public ApiResponse<PageData<SystemNoticeVO>> findPage (@RequestBody PageWrap<QuerySystemNoticeDTO> pageWrap) {
        return ApiResponse.success(systemNoticeBiz.findPage(pageWrap));
    }
}
